<!--
Copyright © 2017, Che-Wei Hsu <cwxhsu@gmail.com>
This file is part of the MintCM.
Some rights reserved. See README.
-->

<html>

<head>

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script language="javascript" type="text/javascript" src="jquery_main.js"></script>
<script language="javascript" type="text/javascript" src="jquery_form.js"></script>
<script language="javascript" type="text/javascript" src="mcm_jslib_api.js"></script>
<link rel="stylesheet" href="web_app_0901_style.css">

<script type="text/javascript">
function body_init()
{
    var self_jslib, req_cmd, rep_ret, mcm_dv;


    $("#last_upload_file_name").html("");
    $("#last_upload_file_size").html("");
    $("#last_upload_save_path").html("");
    $("#last_upload_addition_data").html("");
    $("#show_box").html("");

    // 指定要讀出的資料.
    req_cmd = "&get.device.web_upload";

    // 送出讀出資料請求.
    self_jslib = new mcm_jslib_lib_t();
    self_jslib.socket_path = "@mintcm";
    self_jslib.session_permission = mcm_session_permission.ro;
    self_jslib.session_stack_size = 0;
    self_jslib.request_command = req_cmd;
    self_jslib.data_format = mcm_data_format.all_default;
    self_jslib.other_query = "";
    rep_ret = mcm_jslib_obtain_config(self_jslib);
    if(rep_ret.rep_code < mcm_return_code.pass)
    {
        alert("call mcm_jslib_obtain_config() fail" +
              "[" + rep_ret.rep_code + "]");
        mcm_jslib_run_script(rep_ret.rep_data);
        return;
    }
    // 處理資料格式.
    mcm_dv = JSON.parse(rep_ret.rep_data);

    // 顯示 device.web_upload
    $("#last_upload_file_name").html(
        mcm_jslib_convert_html_str(mcm_dv.device.web_upload.file_name));
    $("#last_upload_file_size").html(mcm_dv.device.web_upload.file_size);
    $("#last_upload_save_path").html(
        mcm_jslib_convert_html_str(mcm_dv.device.web_upload.save_path));
    $("#last_upload_addition_data").html(
        mcm_jslib_convert_html_str(mcm_dv.device.web_upload.addition_data));
}

function upload_file()
{
    var self_upload_jslib, rep_ret;


    if($("#input_file").val() == "")
    {
        alert("no select any file");
        return;
    }

    $("#show_box").html("");

    self_upload_jslib = new mcm_upload_jslib_t();
    self_upload_jslib.form_id_string = "form_upload";
    self_upload_jslib.other_query = "";
    rep_ret = mcm_jslib_upload(self_upload_jslib);
    if(rep_ret.rep_code < mcm_return_code.pass)
    {
        alert("call mcm_jslib_upload() fail" +
              "[" + rep_ret.rep_code + "]");
        mcm_jslib_run_script(rep_ret.rep_data);
        return;
    }
    mcm_jslib_run_script(rep_ret.rep_data);
}
</script>

</head>

<body onload="body_init()">

  <div>[single file input]</div>
  <div>[cgi access config]</div>

  <form id="form_upload">
    <input type="hidden" name="callback" value="upload_handle_02">
    <table class="css_table1">
      <tr>
        <td class="css_td1">file</td>
        <td class="css_td1">
          <input type="file" name="input_file" id="input_file" value="">
        </td>
      </tr>
      <tr>
        <td class="css_td1">addition text</td>
        <td class="css_td1">
          <input type="text" name="input_text" value="">
        </td>
      </tr>
    </table>
  </form>

  <button type="button" onclick="upload_file()">upload</button>
  <br><br>

  <table class="css_table1">
    <tr>
      <td class="css_td1" colspan="2">last upload file information</td>
    </tr>
    <tr>
      <td class="css_td1">file name</td>
      <td class="css_td1" id="last_upload_file_name"></td>
    </tr>
    <tr>
      <td class="css_td1">file size</td>
      <td class="css_td1" id="last_upload_file_size"></td>
    </tr>
    <tr>
      <td class="css_td1">save path</td>
      <td class="css_td1" id="last_upload_save_path"></td>
    </tr>
    <tr>
      <td class="css_td1">addition data</td>
      <td class="css_td1" id="last_upload_addition_data"></td>
    </tr>
  </table>
  <br>

  <div id="show_box"></div>

</body>

</html>
